<?php
$error_msg = '';
switch($action){
    case 'logout':
        clearcookies();
        header('location:'.APP_URL.'/index.php/admin/login/errormsg/'. urlencode('注销成功'));
        exit();
        break;
    case 'login':
        if ($_POST['keystring'] != $_DCOOKIE['authnum']) {
            $error_msg = '验证码错误';
        } else {
            $username = trim($username);
            $password = md5(trim($password));
            $loginuser = $db->fetch_first("SELECT `id`,`username`,`admin_type`,`rank_type`,`give_type`,`status` FROM `system_user` WHERE `username`='{$username}' and `password`='{$password}'");
            if ($loginuser) {
                switch($loginuser['status']){
                    case 'OK':
                        dsetcookie('auth', authcode("{$loginuser['id']}\t$password", 'ENCODE'));
                        $user_info = array2json(array(
                            'username'=>$loginuser['username'],
                            'admin_type'=>$admin_type_list[$loginuser['admin_type']],
                            'rank_type'=>$rank_type_list[$loginuser['rank_type']],
                            'give_type'=>$give_type_list[$loginuser['give_type']]
                        ));
                        dsetcookie('userinfo',$user_info,86400 * 30);
                        header('location:'.APP_URL.'/index.php/admin/index');
                        exit();
                        break;
                    case 'DISABLED':
                        $error_msg = '对不起，您的帐号已被禁用';
                        break;
                    case 'DEL':
                        $error_msg = '对不起，您的帐号已被删除';
                        break;
                    default:
                        $error_msg = '对不起，登入失败';
                        break;
                }
            } else {
                $error_msg = '对不起，账号信息有错';
            }
        }
    default:
        $errormsg && $error_msg = urldecode($errormsg);
        break;
}
?>